package org.magento.pages;

import org.magento.data.CustomerData;
import org.magento.data.NewCustomerData;
import org.magento.utils.ConfigProperties;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

/* This class presents /customer/account/create/page
 */
public class CreateCustomerAccount extends Page {
	
	//Locators:
	@FindBy (id = "firstname")
	public WebElement firstNameField;
	
	@FindBy (id = "lastname")
	public WebElement lastNameField;
	
	@FindBy (id = "email_address")
	public WebElement emailAddressField;
	
	@FindBy (id = "is_subscribed")
	public WebElement newsletterCheckBox;
	
	@FindBy (id = "password")
	public WebElement passwordField;
	
	@FindBy (id = "confirmation")
	public WebElement confirmPasswordField;
	
	@FindBy (xpath = "/html/body/div/div/div[3]/div/div/div/form/div[3]/button")
	public WebElement submitButton;
	
	//Functions:
	public  MyDashboard createNewCustomer(NewCustomerData newCustomer) {
		type(firstNameField, newCustomer.firstName);
		type(lastNameField, newCustomer.lastName);
		type(emailAddressField, newCustomer.email);
		newsletterCheckBox.click();
		type(passwordField, newCustomer.password);
		type(confirmPasswordField, newCustomer.password);
		submitButton.click();
		return PageFactory.initElements(driver, MyDashboard.class);	
	}
	
	public  MyDashboard createCustomer(CustomerData customer) {
		type(firstNameField, customer.firstName);
		type(lastNameField, customer.lastName);
		type(emailAddressField, customer.email);
		newsletterCheckBox.click();
		type(passwordField, customer.password);
		type(confirmPasswordField, customer.password);
		submitButton.click();
		return PageFactory.initElements(driver, MyDashboard.class);	
	}

	
	// Auto-generated
	public CreateCustomerAccount(WebDriver driver) {
		super(driver);
	}

	@Override
	public void open() {
	 driver.get(ConfigProperties.getProperty("url.createCustomer"));
		
	}
}
